package airthmetic.exercise.string;

public class _344_反转字符串 {

    public void reverseString(char[] s) {
        int n = s.length - 1;
        for(int i=0; i<=n >> 1; i++){
            swap(s, i, n-i);
        }
    }

    public void swap(char[] s, int left, int right){
        if(left == right){
            return;
        }
        s[left] ^= s[right];
        s[right] ^= s[left];
        s[left] ^= s[right];

        // char temp = s[left];
        // s[left] = s[right];
        // s[right] = temp;
    }

    public static void main(String[] args) {
        char[] s = {'A',' ','m','a','n',',',' ','a',' ','p','l','a','n',',',' ','a',' ','c','a','n','a','l',':',' ','P','a','n','a','m','a'};
        _344_反转字符串 v = new _344_反转字符串();
        v.reverseString(s);
        
        
        char a = 'n';
        char b = 'w';
        a ^=b;
        b ^=a;
        a ^=b;
        System.out.println(a);
        System.out.println(b);
        
    }
}
